# delimit;
set more off;

* Users should download April08c.sav and convert to .dta;
use April08c.dta, clear;

recode q21aF1 (5/9=.)(1=4)(2=3)(3=2)(4=1), gen(opfed);
recode q21bF1 (.=.a)(5/9=.)(1=4)(2=3)(3=2)(4=1), gen(opst);
recode q21cF1 (5/9=.)(1=4)(2=3)(3=2)(4=1), gen(oploc);
recode q21dF2 (5/9=.)(1=4)(2=3)(3=2)(4=1), gen(opnews);
recode q21eF2 (5/9=.)(1=4)(2=3)(3=2)(4=1), gen(opmilit);
recode q21fF2 (5/9=.)(1=4)(2=3)(3=2)(4=1), gen(opbusin);
recode q21gF2 (5/9=.)(1=4)(2=3)(3=2)(4=1), gen(opsc);	
	
label define opinions_rev

	4 "Very favorable"   
	3 "Mostly favorable"      
	2 "Mostly unfavorable"      
	1 "Very unfavorable"  ;
 
foreach var in busin news milit fed st loc {;
	label values op`var' opinions_rev;
	};
	

recode q1 (1=1 "Approve")(2=0 "Disapprove")(9=.), gen(approve);
label var approve "President Job Approval";


recode sex (1=1)(2=0), gen(r_male);

recode age (99=.), gen(r_age);

recode educ (9=.), gen(r_educ);

recode hisp (1=1)(2=0)(9=.), gen(r_hisp);

recode race (1=1)(2/4=0)(9=.), gen(r_white);
   replace r_white=0 if r_hisp==1;

recode race (2=1)(1=0)(3/4=0)(9=.), gen(r_black);
   replace r_black=0 if r_hisp==1;
   
recode race (3=1)(1 2=0)(4=0)(9=.), gen(r_asian);
   replace r_asian=0 if r_hisp==1;   

recode marital 	(1=1 "Married")
				(2 3=2 "Divorced or Seperated")
				(4=3 "Widowed")
				(5=4 "Single")(9=.), gen(r_marital);
tab marital, gen(r_marital);

recode income (10=.), gen(r_income);

recode attend 	(6=1 "Never")
				(5=2 "Seldom")
				(4=3 "A few times a year")
				(3=4 "Once or twice a month")
				(2=5 "Once a week")
				(1=6 "More than once a week")
				(7/9=.), gen(r_attend);

recode born (1=1)(2=0)(.=0)(9=.), gen(r_bornagn);

recode regist
           (1=1 "Yes, registered")
           (2=0 "No, not registered")
           (9=. ), gen(r_regist);

recode party (1=1)(2/5=0)(9=.), gen(gop);
recode party (1=0)(2=1)(3/5=0)(9=.), gen(dem);
recode party (1/2=0)(3/5=1)(9=.), gen(ind);

recode party (1=1 "Republican")(2=5 "Democrat") (3/5=3 "Independent")(9=.), gen(partyid);
replace partyid=2 if partyid==3 & partyln==1;
replace partyid=3 if partyid==3 & partyln==9;
replace partyid=4 if partyid==3 & partyln==2;

recode ideo (9=.), gen(ideo_all);
tab ideo_all, gen(ideo);

recode employ (9=.);
tab employ, gen(employ);

recode labor (1/3=1 "Yes")(4=0 "No")(9=.), gen(r_union);

recode q22 (5/9=.)(1=4)(2=3)(3=2)(4=1), gen(ecocond_nat);
label var ecocond_nat "Rate economic conditions: National";
recode q23 (5/9=.)(1=4)(2=3)(3=2)(4=1), gen(ecocond_per);
label var ecocond_per "Rate economic conditions: Personal";

gen year=2008;

tostring fips, replace;
gen new=substr(fips, -3, 3);
destring fips, replace;
destring new, replace;
replace fips=(fips-new)/1000;
drop new;

keep fips r_* op* approve gop dem ind partyid ideo* employ* ecocond* year weight zip*;

codebook r_* op* approve gop dem ind partyid ideo* employ* ecocond*;
